from django.db import models
from user.models import CustomUser
from main.models import Anime

# Create your models here.


class AnimeHistory(models.Model):
    user = models.ForeignKey(verbose_name="用户", to=CustomUser, on_delete=models.CASCADE)
    anime = models.ForeignKey(verbose_name="番剧", to=Anime, on_delete=models.CASCADE)
    watched_at = models.DateTimeField(verbose_name="观看时间", auto_now_add=True)

    def __str__(self):
        return f"{self.user.username}观看了{self.anime.title}"

    class Meta:
        verbose_name = "历史记录"
        verbose_name_plural = "历史记录"
        unique_together = [("user", "anime")]
        ordering = ['-watched_at']  # 按照观看时间降序排列